package org.msfj.admin.data.controller;

import org.msfj.admin.model.DictIndex;
import org.msfj.admin.vo.DictIndexVo;
import org.msfj.common.exception.BusinessException;
import org.msfj.admin.data.service.DictIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统数据字典索引信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:20
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统数据字典索引信息接口", tags = "系统数据字典索引信息接口")
@RestController
@RequestMapping("data/dictIndex")
public class DictIndexController extends BaseController{

    @Autowired
    private DictIndexService dictIndexService;

    /**
     * 添加系统数据字典索引信息
     *
     * @param dicIndexVo
     * @return CommonResult.ok(DictIndexVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统数据字典索引信息",notes = "添加系统数据字典索引信息")
    @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query")
    public CommonResult addDicIndex(DictIndexVo dicIndexVo){
        List<DictIndexVo> list = this.dictIndexService.getDictIndexByKey(dicIndexVo.getKey());
        if(!list.isEmpty()){
            throw new BusinessException("字典索引重复，请重新填写！");
        }
        DictIndex dictIndex = dictIndexService.saveOrEdit(dicIndexVo);
        return CommonResult.ok(dictIndexService.setOtherProperties(dictIndex));
    }

    /**
     * 修改系统数据字典索引信息
     *
     * @param dicIndexVo
     * @return CommonResult.ok(DictIndexVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统数据字典索引信息",notes = "修改系统数据字典索引信息")
    @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query")
    public CommonResult editDicIndex(DictIndexVo dicIndexVo){
        DictIndex dictIndex = dictIndexService.saveOrEdit(dicIndexVo);
        return CommonResult.ok(dictIndexService.setOtherProperties(dictIndex));
    }

    /**
     * 逻辑删除系统数据字典索引信息
     *
     * @param dicIndexVo
     * @return CommonResult.ok(DictIndexVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统数据字典索引信息",notes = "逻辑删除系统数据字典索引信息")
    @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query")
    public CommonResult delDicIndex(DictIndexVo dicIndexVo){
        DictIndex dictIndex = dictIndexService.delById(dicIndexVo);
        return CommonResult.ok(dictIndexService.setOtherProperties(dictIndex));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统数据字典索引信息",notes = "逻辑删除系统数据字典索引信息")
    @ApiImplicitParam(value = "ids[]",name = "ids[]",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam(value = "ids[]",required = false) List<String> ids){
        DictIndex dictIndex = new DictIndex();
        dictIndexService.delByIds(ids, dictIndex);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统数据字典索引信息
     *
     * @param dicIndexVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统数据字典索引信息",notes = "真实删除系统数据字典索引信息")
    @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query")
    public CommonResult deleteDicIndex(DictIndexVo dicIndexVo){
        dictIndexService.trueDelById(dicIndexVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统数据字典索引信息
     *
     * @param dicIndexVo
     * @return CommonResult.ok(DictIndexVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统数据字典索引信息",notes = "根据id查找系统数据字典索引信息")
    @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query")
    public CommonResult getDicIndex(DictIndexVo dicIndexVo){
        DictIndex dictIndex = dictIndexService.getById(dicIndexVo.getId());
        return CommonResult.ok(dictIndexService.setOtherProperties(dictIndex));
    }

    /**
     * 根据翻页参数、搜索参数查找系统数据字典索引信息
     *
     * @param dicIndexVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<DictIndexVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统数据字典索引信息",notes = "根据翻页参数、搜索参数查找系统数据字典索引信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findDicIndexList(DictIndexVo dicIndexVo, Integer page, Integer rows){
        PageInfo<DictIndexVo> dicIndexVoPageInfo = dictIndexService.getByDicIndex(dicIndexVo,page,rows);
        return CommonResult.ok(dicIndexVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统数据字典索引信息
     *
     * @param dicIndexVo
     * @return CommonResult.ok(List<DictIndexVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统数据字典索引信息",notes = "根据搜索参数查找所有系统数据字典索引信息")
    @ApiImplicitParam(value = "dicIndexVo",name = "dicIndexVo",dataType = "org.msfj.admin.vo.DictIndexVo",paramType = "query")
    public CommonResult getAllDicIndex(DictIndexVo dicIndexVo){
        List<DictIndexVo> dicIndexVoList = dictIndexService.getAllDicIndex(dicIndexVo);
        return CommonResult.ok(dicIndexVoList);
    }
}
